package com.icinfo.cloud.provider.punish.api.controller;

import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.punish.api.dto.ApiSimpleCaseDetailInfoCallbackDto;
import com.icinfo.cloud.provider.punish.api.dto.ApiSimpleCaseDetailInfoDto;
import com.icinfo.cloud.provider.punish.api.dto.ApiSimpleCaseTemporaryCacheDto;
import com.icinfo.cloud.provider.punish.api.service.IApiSimpleCaseDetailInfoCallbackService;
import com.icinfo.cloud.provider.punish.api.service.IApiSimpleCaseService;
import com.icinfo.cloud.provider.punish.api.vo.ApiSimpleCaseDetailInfoVo;
import com.icinfo.framework.common.web.Result;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.net.util.Base64;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.util.UriUtils;

import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;

/**
 * 描述：简易处罚应用接口控制器
 * @author xiangyuyu
 * @date 2022/8/11
 * @since 1.3.2
 */
@RestController
@RequestMapping("/punish/api/simpleCase")
public class ApiSimpleCaseController {
    @Resource
    private IApiSimpleCaseService apiSimpleCaseService;
    @Resource
    private IApiSimpleCaseDetailInfoCallbackService iApiSimpleCaseDetailInfoCallbackService;

    /**
     * 【V1.3.2】描述：api-简易处罚信息缓存
     *
     * @param dto {@link ApiSimpleCaseTemporaryCacheDto}
     * @return Result<String> 缓存结果
     * @author xiangyuyu
     * @date 2022/8/11
     * @since 1.3.2
     */

    @PostMapping("/simpleCaseTemporaryCache")
    @ApiOperation(value = "【V1.3.2】描述：api-简易处罚信息缓存", httpMethod = "POST")
    public Result<String> simpleCaseTemporaryCache(@Validated @RequestBody ApiSimpleCaseTemporaryCacheDto dto) {
        return apiSimpleCaseService.simpleCaseTemporaryCache(dto);
    }

    /**
     * 【V1.3.2】描述：获取简易处罚案件详情
     *
     * @param dto {@link ApiSimpleCaseDetailInfoDto}
     * @return Result<ApiSimpleCaseDetailInfoVo> 简易处罚案件详情
     * @author xiangyuyu
     * @date 2022/8/11
     * @since 1.3.2
     */

    @PostMapping("/getSimpleCaseDetailInfo")
    @ApiOperation(value = "【V1.3.2】获取案件详情", httpMethod = "POST")
    public Result<ApiSimpleCaseDetailInfoVo> getSimpleCaseDetailInfo(@RequestBody @Validated ApiSimpleCaseDetailInfoDto dto) {
        ApiSimpleCaseDetailInfoVo vo = apiSimpleCaseService.getSimpleCaseDetailInfo(dto);
        if(ObjectUtils.isEmpty(vo)){
            return Result.error("未获取到简易处罚案件详情信息");
        }
        return Result.success(Constant.STRING_GET_SUCCESS, vo);
    }



    /**
     * 【V1.3.2】描述：简易处罚信息回流
     *
     * @param dto {@link ApiSimpleCaseDetailInfoCallbackDto}
     * @return Result<String> 回流结果
     * @author xiangyuyu
     * @date 2022/8/11
     * @since 1.3.2
     */
    @PostMapping("/callbackSimpleCaseDetailInfo")
    @ApiOperation(value = "【V1.3.2】简易处罚信息回流", httpMethod = "POST")
    public Result<String> callbackSimpleCaseDetailInfo(@RequestBody @Validated ApiSimpleCaseDetailInfoCallbackDto dto) {
        return iApiSimpleCaseDetailInfoCallbackService.callbackSimpleCaseDetailInfo(dto);
    }
}
